home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Un ejercicio de presentación de texto / SysInfoReflection / SysInfoReflection.cs next >
Encoding:
Text File  |  2002-05-16  |  2.7 KB  |  86 lines

  1. //-----------------------------------------------
  2. // SysInfoReflection.cs ⌐ 2001 by Charles Petzold
  3. //-----------------------------------------------
  4. using Microsoft.Win32;
  5. using System;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8.  
  9. class SysInfoReflection: Form
  10. {
  11.      protected int      iCount;
  12.      protected string[] astrLabels;
  13.      protected string[] astrValues;
  14.      protected float    cxCol;
  15.      protected int      cySpace;
  16.  
  17.      public static void Main()
  18.      {
  19.           Application.Run(new SysInfoReflection());
  20.      }
  21.      public SysInfoReflection()
  22.      {
  23.           Text = "Informaci≤n del Sistema: Reflexi≤n";
  24.           BackColor = SystemColors.Window;
  25.           ForeColor = SystemColors.WindowText;
  26.           AutoScroll = true;
  27.  
  28.           SystemEvents.UserPreferenceChanged += 
  29.                new UserPreferenceChangedEventHandler(UserPreferenceChanged);
  30.  
  31.           SystemEvents.DisplaySettingsChanged +=
  32.                new EventHandler(DisplaySettingsChanged);
  33.  
  34.           UpdateAllInfo();
  35.      }
  36.      void UserPreferenceChanged(object obj, UserPreferenceChangedEventArgs ea)
  37.      {
  38.           UpdateAllInfo();
  39.           Invalidate();
  40.      }
  41.      void DisplaySettingsChanged(object obj, EventArgs ea)
  42.      {
  43.           UpdateAllInfo();
  44.           Invalidate();
  45.      }
  46.      void UpdateAllInfo()
  47.      {
  48.           iCount     = SysInfoReflectionStrings.Count;
  49.           astrLabels = SysInfoReflectionStrings.Labels;
  50.           astrValues = SysInfoReflectionStrings.Values;
  51.  
  52.           Graphics grfx  = CreateGraphics();
  53.           SizeF    sizef = grfx.MeasureString(" ", Font);
  54.           cxCol  = sizef.Width + 
  55.                          SysInfoReflectionStrings.MaxLabelWidth(grfx, Font);
  56.           cySpace = Font.Height;
  57.  
  58.           AutoScrollMinSize = new Size(
  59.               (int) Math.Ceiling(cxCol + 
  60.                          SysInfoReflectionStrings.MaxValueWidth(grfx, Font)),
  61.               (int) Math.Ceiling(cySpace * iCount));
  62.  
  63.           grfx.Dispose();
  64.      }
  65.      protected override void OnPaint(PaintEventArgs pea)
  66.      {
  67.           Graphics grfx  = pea.Graphics;
  68.           Brush    brush = new SolidBrush(ForeColor);
  69.           Point    pt    = AutoScrollPosition;
  70.  
  71.           int iFirst = (int)((pea.ClipRectangle.Top    - pt.Y) / cySpace);
  72.           int iLast  = (int)((pea.ClipRectangle.Bottom - pt.Y) / cySpace);
  73.  
  74.           iLast = Math.Min(iCount - 1, iLast);
  75.  
  76.           for (int i = iFirst; i <= iLast; i++)
  77.           {
  78.                grfx.DrawString(astrLabels[i], Font, brush, 
  79.                                pt.X, pt.Y + i * cySpace);
  80.  
  81.                grfx.DrawString(astrValues[i], Font, brush, 
  82.                                pt.X + cxCol, pt.Y + i * cySpace); 
  83.           }
  84.      }
  85. }
  86.